package gui;

import java.awt.AlphaComposite;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

@SuppressWarnings("serial")
public class HelpPanel extends JPanel {

	public HelpPanel() {
		setEnvironment();

		JPanel temp = new JPanel(new GridBagLayout());
		temp.setOpaque(false);
		GridBagConstraints c = new GridBagConstraints();

		ImageIcon icon = new ImageIcon(ImagesDirectory.getHelpPanelBG());
		final Image backgroundImage = icon.getImage();

		JTextArea textArea = new JTextArea(getHelpInfo()) {
			@Override
			protected void paintComponent(Graphics g) {
				Graphics2D g2d = (Graphics2D) g;

				g2d.setComposite(AlphaComposite.getInstance(
						AlphaComposite.SRC_OVER, 0.85f));
				g2d.drawImage(backgroundImage, 0, 0, Dimensions._windowWidth,
						Dimensions._windowHeight * 2, null);
				super.paintComponent(g2d);
			}
		};
		textAreaEnvironment(textArea);

		JScrollPane scrollpane = new JScrollPane(textArea);
		scrollpaneEnvironment(scrollpane);

		c.fill = GridBagConstraints.HORIZONTAL;
		c.weightx = 0.5;
		c.gridx = 0;
		c.gridy = 0;
		temp.add(scrollpane, c);

		add(temp, BorderLayout.CENTER);
	}

	private void scrollpaneEnvironment(JScrollPane scrollpane) {
		scrollpane.setOpaque(false);
		scrollpane.getViewport().setOpaque(false);
		scrollpane.setPreferredSize(new Dimension(Dimensions._scrollPaneWidth,
				Dimensions._scrollPaneHeight));
		scrollpane.setMinimumSize(new Dimension(Dimensions._scrollPaneWidth,
				Dimensions._scrollPaneHeight));
		scrollpane.setMaximumSize(new Dimension(Dimensions._scrollPaneWidth,
				Dimensions._scrollPaneHeight));
	}

	private void textAreaEnvironment(JTextArea textArea) {
		textArea.setOpaque(false);
		textArea.setFont(new java.awt.Font("Comic Sans MS", Font.BOLD, 12));
		textArea.setForeground(new Color(255, 255, 255));
		textArea.setEditable(false);
		textArea.setPreferredSize(new Dimension(Dimensions._textAreaWidth,
				Dimensions._textAreaHeight));
		textArea.setMinimumSize(new Dimension(Dimensions._textAreaWidth,
				Dimensions._textAreaHeight));
		textArea.setMaximumSize(new Dimension(Dimensions._textAreaWidth,
				Dimensions._textAreaHeight));
		textArea.setAutoscrolls(true);
	}

	private void setEnvironment() {
		setLayout(new BorderLayout());
		setSize(Dimensions._windowWidth, Dimensions._windowHeight);
		setOpaque(false);
	}

	private String getHelpInfo() {
		String info = "AVAILABLE TIME FORMAT\n"
				+ "HHmm HH.mm HH:mm H:mma h.mma ha hha\n"
				+ "H -> Hour m -> minutes a -> am/pm \n\n"
				+ "AVAILABLE DATE FORMAT\n"
				+ "dd/M/yyyy dd/M/yy dd/MM/yyy dd/MM/yy d/M/yyyy d/M/yyy\n"
				+ "d/MM/yyyy d/MM/yy dd-M-yyyy dd-M-yy dd-MM-yyyy dd-MM-yy\n"
				+ "d-M-yyyy d-M-yy d-MM-yyyy d-MM-yy dd.M.yyyy dd.M.yy\n"
				+ "dd.MM.yyyy dd.MM.yy d.M.yyyy d.M.yy d.MM.yyyy d.MM.yy\n"
				+ "d -> day m -> month y -> year\n\n\n"
				+ "\t~FEATURES OF FORGETMENOT~\n\n"
				+ "ADD TASKS\n"
				+ "add <EndDate><EndTime><Task>\n"
				+ "add <StartTime><EndTime><EndDate><Task>\n"
				+ "add <StartDate><EndDate><Task>\n"
				+ "add <StartDate><StartTime><EndDate><EndTime><Task>\n"
				+ "add <StartDate><EndDate><EndTime>\n"
				+ "add <Task>\n\n"
				+ "DELETE TASKS\n"
				+ "del <index>\t"
				+ "Deletes tasks at specified index.\n\n"
				+ "DISPLAY TASKS\n"
				+ "dis a\t"
				+ "Display all non-expired tasks.\n"
				+ "dis t\t"
				+ "Display all non-expired timed tasks.\n"
				+ "dis f\t"
				+ "Display all non-expired floating tasks.\n\n"
				+ "EDIT TASKS\n"
				+ "edi <index> st <Task>\t"
				+ "Edits only the start time of specified task.\n"
				+ "edi <index> et <Task>\t"
				+ "Edits only the end time of specified task.\n"
				+ "edi <index> sd <Task>\t"
				+ "Edits only the start date of specified task.\n"
				+ "edi <index> ed <Task>\t"
				+ "Edits only the end date of specified task.\n"
				+ "edi <index> bd <StartDate><EndDate>\t"
				+ "Edits both start and end date of specified task.\n"
				+ "edi <index> bt <StartDate><EndDate>\t"
				+ "Edits both start and end time of specified task.\n"
				+ "edi <index> d <Task>\t"
				+ "Edits the task description of specified task.\n"
				+ "*You can edit several elements of the task at the same time specifying the edit type\n"
				+ "i.e. edi <index> bd <StartDate><EndDate> st <startTime><EndTime> t <newTask>\n\n"
				+ "SEARCH WORD\n"
				+ "src <keyword>\t"
				+ "Search for tasks that contains keyword.\n\n"
				+ "UNDO\n"
				+ "undo\t"
				+ "Undo the previous action made that alters the existing list of tasks; i.e. add/delete/edit task\n\n"
				+ "REDO\n"
				+ "redo\t"
				+ "Redo the previous undone action, if there is none, does nothing.";

		return info;
	}
}